package com.mybatis.demo.controller;

import com.mybatis.demo.common.ResponseData;
import com.mybatis.demo.pojo.dto.SaveDeptDto;
import com.mybatis.demo.pojo.dto.UpdateDeptDto;
import com.mybatis.demo.pojo.dto.getPageDeptDto;
import com.mybatis.demo.pojo.po.BaseWorker;
import com.mybatis.demo.service.DeptService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 *@ClassName DeptController
 *@Author 郭承乐
 *@Date 2024/8/21 13:57
 *@Version 1.0
 **/
@Api(tags = "员工管理")
@RestController
@RequestMapping("/dept")
public class DeptController {
    private final DeptService deptService;
    public DeptController(DeptService deptService) {
        this.deptService = deptService;
    }

    /**
     * @Description 
     * @Author 郭承乐
     * @Date 16:15 2024/8/21
     * @Param [dto]
     * @Return com.mybatis.demo.common.ResponseData
     **/
    @ApiOperation("新增员工")
    @PostMapping("saveDept")
    public ResponseData saveDept(@RequestBody SaveDeptDto dto) {
        deptService.saveDept(dto);
        return ResponseData.success(null);
    }

    @ApiOperation("删除员工")
    @DeleteMapping("/deleteDept/{id}")
    public ResponseData deleteDept(@PathVariable Integer id) {
        deptService.deleteDept(id);
        return ResponseData.success(null);
    }

    @ApiOperation("更新员工")
    @PutMapping("/updateDept")
    public ResponseData updateDept(@RequestBody UpdateDeptDto dto) {
        deptService.updateDept(dto);
        return ResponseData.success(null);
    }

    @ApiOperation("获取所有员工")
    @GetMapping("/getDeptList")
    public ResponseData getDeptList() {
        List<BaseWorker> baseWorkers =deptService.listDept();
        return ResponseData.success(baseWorkers);
    }

    @ApiOperation("分页查询员工")
    @GetMapping("/getPageDept")
    public ResponseData getPageDept(getPageDeptDto dto) {
        List<BaseWorker> baseWorkers = deptService.getPageDept(dto);
        return ResponseData.success(baseWorkers);
    }
}
